{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# t-SNE(t-分布随机邻域嵌入)算法\n",
    "from sklearn.manifold import TSNE # 导入t-SNE算法\n",
    "from sklearn.datasets import load_digits # 导入手写数字数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\admin\\anaconda3\\envs\\ml\\lib\\site-packages\\sklearn\\manifold\\_t_sne.py:783: FutureWarning: The default initialization in TSNE will change from 'random' to 'pca' in 1.2.\n",
      "  FutureWarning,\n",
      "c:\\Users\\admin\\anaconda3\\envs\\ml\\lib\\site-packages\\sklearn\\manifold\\_t_sne.py:793: FutureWarning: The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.\n",
      "  FutureWarning,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-71.0715     -2.318061 ]\n",
      " [  3.9923482 -15.013521 ]\n",
      " [ -9.672771    7.9468145]\n",
      " ...\n",
      " [  1.4678006   6.770663 ]\n",
      " [  9.993241   40.69267  ]\n",
      " [  0.501386   13.137217 ]]\n"
     ]
    }
   ],
   "source": [
    " data = load_digits() # 加载手写数字数据集\n",
    " n_components = 2  # 设置降维后的维度为2\n",
    " model = TSNE(n_components=n_components) # 创建t-SNE模型\n",
    " print(model.fit_transform(data.data))  # 训练模型并转换数据"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
